<%@ Page Language="vb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script  runat="server">
Sub Page_Load(sender As Object, e As EventArgs)		
    	Dim myConnString= "server=localhost;" & _
	"UID=sa;PWD=aido;database=intershop;" & _
	"Connect Timeout=30"
	Dim mySelectQuery  = "SELECT * FROM tblItems"
    	Dim myConnection As New SqlConnection(myConnString)	
    	myConnection.Open()

	Dim myCommand As SqlCommand = _
	myConnection.CreateCommand()
    	Dim myTrans As SqlTransaction
       	
   	 myTrans = myConnection.BeginTransaction( _
	IsolationLevel.ReadCommitted, "SampleTransaction")
   	 ' Must assign both transaction object and connection
	' to Command object for a pending local transaction
	myCommand.Connection = myConnection
    	myCommand.Transaction = myTrans
    	Try
      	myCommand.CommandText = "Insert into " & _
	"tblSubCategory (SubCateName) " & _
	" VALUES ('ASP 3.0 Description')"
      	myCommand.ExecuteNonQuery()
      	myCommand.CommandText = "Insert into " & _
	"tblSubCategories (SubCateName) " & _
	" VALUES ('ASPX Description')"
      	myCommand.ExecuteNonQuery()
      	myTrans.Commit()
      	Response.Write("Both records are written to database.")
    	Catch ex As Exception
		Try
        		myTrans.Rollback("SampleTransaction")
      		Catch sqlex As SqlException
        		If Not myTrans.Connection Is Nothing Then
          			Response.Write("An SQL exception of type ")
			Response.Write(sqlex.GetType().ToString() & _
                            	"<br> was encountered while attempting to ")
			Response.Write("roll back the transaction.<br><br>")
        		End If
      		End Try
    
      		Response.Write("An exception of type " & _
		ex.GetType().ToString() & _
                     	 " <br> was encountered while inserting the data.<br>")
      		Response.Write("Neither record was written to database.")
    	Finally
     		 myConnection.Close()
    	End Try
End Sub
</script>	
